package lc.smart.android.util;

import lc.smart.android.main.SmartApplication;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.util.Log;

public class ImagesUtil
{
	public static final String TAG_STRING = "ImagesUtil";//标识

	public static Bitmap getBitmap(String imageFilePathString, int with,
			int height)
	{
		//加载大图片并并房子oom
		//获取屏幕大小
		//Display currentDisplay = getWindowManager().getDefaultDisplay();
		int dw = with;
		int dh = height;
		//加载图像尺寸而不是图像本身
		BitmapFactory.Options bmpFactoryOptions = new BitmapFactory.Options();
		bmpFactoryOptions.inJustDecodeBounds = true;
		Bitmap bitmap = BitmapFactory.decodeFile(imageFilePathString,
				bmpFactoryOptions);
		int heightRatio = (int) Math.ceil(bmpFactoryOptions.outHeight
				/ (float) dh);
		int widthRatio = (int) Math.ceil(bmpFactoryOptions.outWidth
				/ (float) dw);
		if (SmartApplication.is_DubugMode)
		{
			Log.i(TAG_STRING, "heightRatio:" + heightRatio + " widthRatio:"
					+ widthRatio);

		}
		//如果两个比率都大于1；
		//那么图像的一条边将大于屏幕
		if (heightRatio > 1 && widthRatio > 1)
		{
			if (heightRatio > widthRatio)
			{
				//若高度比率更大，则根据它缩放
				bmpFactoryOptions.inSampleSize = heightRatio;
			}
			else
			{
				//若宽度比率更大，则根据它缩放
				bmpFactoryOptions.inSampleSize = widthRatio;
			}
		}
		//对图像进行真正的解码
		bmpFactoryOptions.inJustDecodeBounds = false;
		bitmap = BitmapFactory.decodeFile(imageFilePathString,
				bmpFactoryOptions);

		return bitmap;
	}

}
